package com.lintf.sharding.sphere.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lintf.business.entity.SysUser;
import com.lintf.common.utils.PageMineUtils;
import com.lintf.sharding.sphere.mapper.SysUserMapper;
import com.lintf.sharding.sphere.service.ISysUserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @description 针对表【t_order】的数据库操作Service实现
 * @createDate 2024-10-24 21:20:16
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements ISysUserService {
    /**
     * PageHelper分页工具：符合预期
     * 第一种实现方式
     *
     * @return
     */
    @Override
    public Map<String, Object> getSysUserListByPageHelperM1() {
        com.github.pagehelper.Page<SysUser> startPage = PageHelper.startPage(1, 10);
        List<SysUser> list = baseMapper.selectList(null);
        Map<String, Object> result = new HashMap<>();
        result.put("total", startPage.getTotal());
        result.put("pages", startPage.getPages());
        result.put("pageNum", startPage.getPageNum());
        result.put("pageSize", startPage.getPageSize());
        result.put("list", list);
        return result;
    }

    /**
     * PageHelper分页工具：符合预期
     * 第二种实现方式
     *
     * @return
     */
    @Override
    public Map<String, Object> getSysUserListByPageHelperM2() {
        PageHelper.startPage(1, 10);
        List<SysUser> list = baseMapper.selectList(null);
        PageInfo<SysUser> pageInfo = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>();
        result.put("total", pageInfo.getTotal());
        result.put("pages", pageInfo.getPages());
        result.put("pageNum", pageInfo.getPageNum());
        result.put("pageSize", pageInfo.getPageSize());
        result.put("list", list);
        return result;
    }

    /**
     * PageHelper分页工具封装工具类：符合预期
     *
     * @return
     */
    @Override
    public Map<String, Object> getSysUserListByPageHelperToUtils() {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        return PageMineUtils.executePaginationByPageHelper(1, 10, baseMapper, wrapper);
    }


    /**
     * MyBatisPlus自带分页：单表分页成功；分表分页失败；参数缺失
     *
     * @return
     */
    @Override
    public Map<String, Object> getSysUserListByMyBatisPlus() {
        Page<SysUser> page = new Page<>(1, 10);
        Page<SysUser> sysUserPage = baseMapper.selectPage(page, null);
        Map<String, Object> result = new HashMap<>();
        result.put("total", sysUserPage.getTotal());
        result.put("pages", sysUserPage.getPages());
        result.put("pageNum", sysUserPage.getCurrent());
        result.put("pageSize", sysUserPage.getSize());
        result.put("list", sysUserPage.getRecords());
        return result;
    }

    /**
     * MyBatisPlus自带分页封装工具类：单表分页成功；分表分页失败；参数缺失
     *
     * @return
     */
    @Override
    public Map<String, Object> getSysUserListByMyBatisPlusToUtils() {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        return PageMineUtils.executePaginationByMyBatisPlus(1, 10, baseMapper, wrapper);
    }
}





